#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define eb emplace_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < ll > vec;
typedef pair < ll , ll > pii;

const int N = 2e5 + 10;

string s;
ll K;
set < pii > V;

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	ios :: sync_with_stdio(false); cin.tie(0);
	cin >> s >> K;
	ll x = 0, y = 0; V.emplace(x, y);
	for(auto c : s) {
		if(c == 'L') x--;
		else if(c == 'R') x++;
		else if(c == 'U') y--;
		else y++;
		V.emplace(x, y);
	}
	vector < pii > t; for(const auto& v : V) t.eb(v);
	auto calc = [](const auto& a, const auto& b) {
					if(a > 0) return a / b;
					else return -((-a + b - 1) / b); 
				};
	if(x == 0) {
		if(y == 0) return cout << t.size() << endl, 0;
		swap(x, y);
		for(auto &v : t) swap(v.fi, v.se);
	}
	if(x < 0) {
		x = -x;
		for(auto &v : t) v.fi = -v.fi; 
	}
	if(y < 0) {
		y = -y;
		for(auto &v : t) v.se = -v.se;
	}
	map < pii, vector < ll > > al;
	for(auto &v : t) {
		ll d = calc(v.fi, x);
		v.fi -= d * x; v.se -= d * y;
		al[v].eb(d);
	} ll ans = 0;
	for(auto &mp : al) {
		sort(mp.se.begin(), mp.se.end());
		ll lst = 0; bool fl = 0;
		for(auto x : mp.se) {
			if(fl) { ans += min(K, x - lst); }
			lst = x; fl = true;
		} ans += K;
	} printf("%lld\n", ans); return 0;
} 
